package cn.laixueit.listener;

import cn.laixueit.cart.service.GoodsCreateHtml;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileNotFoundException;

@Component
public class HtmlListener {

    @Autowired
    GoodsCreateHtml goodsCreateHtml;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "chuangmei.create.web.queue",durable = "true"),
            exchange = @Exchange(value = "chuangmei.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.insert","item.update"}
    ))
    public void createHtml(Long id){
        try {
            goodsCreateHtml.createHtml(id);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "chuangmei.create.web.queue",durable = "true"),
            exchange = @Exchange(value = "chuangmei.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.delete"}
    ))
    public void deleteHtml(Long id){
        System.out.println(id);
        goodsCreateHtml.delteHtml(id);
    }

}
